﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Room1_Contrel : MonoBehaviour
{
    public GameObject[] answer;
    public GameObject warringMachine;
    public GameObject door;
    public GameObject key;
    public GameObject damageTrigger;
    public bool canPrint = true;
    ArrayList array = new ArrayList();
    bool machineStart = false;
    public bool isPass = false;
    //public string[] inputPressName = new string[3];
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if(array.Count>=answer.Length)
        {
            for(int i=0;i<answer.Length;i++)
            {
                if(!array[i].Equals(answer[i]))
                {
                    machineStart = true;
                    break;
                }
                if (answer.Length == array.Count)
                    isPass = true;
            }
        }
        if (machineStart)
        {
            damageTrigger.GetComponent<Trigger_show_room1>().hasDamage = true;
            if (array.Count >= answer.Length)
            {
                warringMachine.GetComponent<WarringControl>().isWarring = true;
                door.GetComponent<Animator>().SetBool("Open", false);
                for (int i = 0; i < array.Count; i++)
                {
                    ((GameObject)array[i]).GetComponent<Animator>().SetBool("Press", false);
                    ((GameObject)array[i]).GetComponent<BoxCollider>().enabled = true;
                }
                array.Clear();
            }
        }
        if(isPass)
        {
            machineStart = false;
            warringMachine.GetComponent<WarringControl>().isWarring = false;
            door.GetComponent<Animator>().SetBool("Open", true);
            damageTrigger.GetComponent<Trigger_show_room1>().hasDamage = false;
            if (canPrint)
            {
                damageTrigger.GetComponent<Trigger_show_room1>().contrelBall.GetComponent<BindShowText>().setShowText("听从旁白的指示才能活下去（也许）");
                damageTrigger.GetComponent<Trigger_show_room1>().contrelBall.GetComponent<BindShowText>().showShowText();
            }
            if (key!=null)
                key.GetComponent<KeyS_Trigger>().apear = true;
        }
    }

    public void addPressObj(GameObject obj)
    {
        array.Add(obj);
    }
}
